import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/enterprise/login',
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('@/views/AboutView.vue'),
    },
    // 超级管理员登录
    {
      path: '/admin/login',
      name: 'admin-login',
      component: () => import('@/views/admin/AdminLogin.vue'),
      meta: {
        title: '超级管理员登录'
      }
    },
    // 企业端登录
    {
      path: '/enterprise/login',
      name: 'enterprise-login',
      component: () => import('@/views/enterprise/backend/auth/EnterpriseLogin.vue'),
      meta: {
        title: '企业登录'
      }
    },

    // 求职者登录
    {
      path: '/seeker/login',
      name: 'seeker-login',
      component: () => import('../views/job_seeker/SeekerLogin.vue'),
      meta: {
        title: '求职者登录'
      }
    },
    // 超级管理员后台
    {
      path: '/admin',
      component: () => import('@/layout/AdminLayout.vue'),
      redirect: '/admin/dashboard',
      meta: {
        title: '超级管理员',
        requiresAuth: true,
        roles: ['SuperAdmin']
      },
      children: [
        {
          path: 'dashboard',
          name: 'admin-dashboard',
          component: () => import('@/views/admin/DashboardView.vue'),
          meta: {
            title: '仪表盘'
          }
        },
        {
          path: 'enterprise/list',
          name: 'admin-enterprise-list',
          component: () => import('@/views/admin/enterprise/list/EnterpriseList.vue'),
          meta: {
            title: '企业管理'
          }
        },
        {
          path: 'enterprise/users',
          name: 'admin-enterprise-users',
          component: () => import('@/views/admin/enterprise/users/EnterpriseUsers.vue'),
          meta: {
            title: '企业用户管理'
          }
        },
        {
          path: 'statistics',
          name: 'admin-statistics',
          component: () => import('@/views/admin/statistics/StatisticsView.vue'),
          meta: {
            title: '数据统计'
          }
        },
        {
          path: 'settings',
          name: 'admin-settings',
          component: () => import('@/views/admin/settings/SettingsView.vue'),
          meta: {
            title: '系统设置'
          }
        }
      ]
    },
    // 企业端后台
    {
      path: '/enterprise',
      component: () => import('@/layout/EnterpriseLayout.vue'),
      redirect: '/enterprise/dashboard',
      meta: {
        title: '企业管理',
        requiresAuth: true,
        roles: ['Admin', 'Recruiter']
      },
      children: [
        {
          path: 'dashboard',
          name: 'enterprise-dashboard',
          component: () => import('@/views/enterprise/home/DashboardView.vue'),
          meta: {
            title: '首页'
          }
        },
        {
          path: 'jobs',
          name: 'enterprise-jobs',
          component: () => import('@/views/enterprise/backend/management/Jobs/JobsView.vue'),
          meta: {
            title: '职位管理'
          }
        },
        {
          path: 'jobs/create',
          name: 'enterprise-jobs-create',
          component: () => import('@/views/enterprise/backend/other/JobCreate/JobCreateView.vue'),
          meta: {
            title: '发布职位'
          }
        },
        {
          path: 'candidates',
          name: 'enterprise-candidates',
          component: () => import('@/views/enterprise/backend/management/Candidates/CandidatesView.vue'),
          meta: {
            title: '候选人管理'
          }
        },
        {
          path: 'resumes',
          name: 'enterprise-resumes',
          component: () => import('@/views/enterprise/backend/management/Resume/ResumeCenter.vue'),
          meta: {
            title: '简历中心'
          }
        },
        {
          path: 'interviews',
          name: 'enterprise-interviews',
          component: () => import('@/views/enterprise/backend/management/Interviews/InterviewsManager.vue'),
          meta: {
            title: '面试管理'
          }
        },
        {
          path: 'offers',
          name: 'enterprise-offers',
          component: () => import('@/views/enterprise/backend/management/Offers/OffersManager.vue'),
          meta: {
            title: 'Offer管理'
          }
        },
        {
          path: 'rejected',
          name: 'enterprise-rejected',
          component: () => import('@/views/enterprise/backend/management/Rejected/RejectedList.vue'),
          meta: {
            title: '已拒绝人员'
          }
        },
        {
          path: 'hr-management',
          name: 'enterprise-hr-management',
          component: () => import('@/views/enterprise/backend/management/HR/HRManagement.vue'),
          meta: {
            title: 'HR管理'
          }
        },
        {
          path: 'employees',
          name: 'enterprise-employees',
          component: () => import('@/views/enterprise/backend/management/Employees/EmployeesManagement.vue'),
          meta: {
            title: '普通员工管理'
          }
        },
        {
          path: 'interviewers',
          name: 'enterprise-interviewers',
          component: () => import('@/views/enterprise/backend/management/Interviewers/InterviewersManagement.vue'),
          meta: {
            title: '面试官管理'
          }
        },
        {
          path: 'company-settings',
          name: 'enterprise-company-settings',
          component: () => import('@/views/enterprise/backend/other/settings/company/CompanySettings.vue'),
          meta: {
            title: '公司设置'
          }
        },
        {
          path: 'system-settings',
          name: 'enterprise-system-settings',
          component: () => import('@/views/enterprise/backend/other/settings/system/SystemSettings.vue'),
          meta: {
            title: '系统设置'
          }
        }
      ]
    },

  ],
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta?.title) {
    document.title = `${to.meta.title} - OrangeHire`
  }

  // TODO: 添加权限验证逻辑
  // if (to.meta?.requiresAuth) {
  //   // 检查登录状态和权限
  // }

  next()
})

export default router
